Skip to content

test(qdrant): replace in-place Document mutations with dataclasses.replace()#3180

Closed
Aftabbs wants to merge 1 commit intodeepset-ai:mainfrom
Aftabbs:fix/qdrant-sparse-embedding-test-mutation
Closed

test(qdrant): replace in-place Document mutations with dataclasses.replace()#3180
Aftabbs wants to merge 1 commit intodeepset-ai:mainfrom
Aftabbs:fix/qdrant-sparse-embedding-test-mutation

Conversation

@Aftabbs
Copy link
Copy Markdown
Contributor

@Aftabbs Aftabbs commented Apr 19, 2026

Summary

partially addresses deepset-ai/haystack#11084 (partial — Qdrant).

After the in-place mutation warning was added to Document in deepset-ai/haystack#10650, four tests in QdrantSparseEmbeddingRetrieverIntegration trigger DeprecationWarning by mutating Document.sparse_embedding and Document.meta directly after construction.

Affected tests and mutations:

Test Field mutated
test_run doc.sparse_embedding
test_run_with_group_by doc.sparse_embedding, doc.meta
test_run_async doc.sparse_embedding
test_run_with_group_by_async doc.sparse_embedding, doc.meta

Fix: replace all for-loop field assignments with dataclasses.replace() list comprehensions:

# Before
for doc in filterable_docs:
    doc.sparse_embedding = generate_sparse_embedding()

# After
filterable_docs = [
    dataclasses.replace(doc, sparse_embedding=generate_sparse_embedding()) for doc in filterable_docs
]

Test plan

  • Run pytest -m "integration" integrations/qdrant/tests/test_sparse_embedding_retriever.py — should pass with zero DeprecationWarning about in-place mutations

@Aftabbs Aftabbs requested a review from a team as a code owner April 19, 2026 15:53
@Aftabbs Aftabbs requested review from bogdankostic and removed request for a team April 19, 2026 15:53
@github-actions
Copy link
Copy Markdown
Contributor

Coverage report (qdrant)

This PR does not seem to contain any modification to coverable code.

@bogdankostic bogdankostic self-assigned this Apr 20, 2026
Copy link
Copy Markdown
Contributor

@bogdankostic bogdankostic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR @Aftabbs! I added a comment about reverting the changes made to CHANGELOG.md - otherwise the PR already looks good.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the changes made here, the Changelog is generated automatically whenever we release a new version.

@anakin87
Copy link
Copy Markdown
Member

Sorry, I already did this change in #3183

@Aftabbs I am closing your PR but thank you again!

@anakin87 anakin87 closed this Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants